<template>
  <div class="user-info">
    <el-dropdown>
      <span class="el-dropdown-link">
        <el-avatar :size="33" :src="userInfo.avatar_url"></el-avatar>
        <span class="user-name">{{ userInfo.first_name }}</span>
        <el-icon class="el-icon--right">
          <arrow-down />
        </el-icon>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="handleLoginOut">退出登录</el-dropdown-item>
          <el-dropdown-item divided>用户信息</el-dropdown-item>
          <el-dropdown-item>系统管理</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script setup lang="ts">
import { LOGIN_TOKEN, ROUTES, USERINFO } from '@/constant'
import router from '@/router'
import { localCache } from '@/utils/cache'

const userInfo = localCache.getCache('userInfo')?.basic_info

const handleLoginOut = () => {
  localCache.removeCache(LOGIN_TOKEN)
  localCache.removeCache(ROUTES)
  localCache.removeCache(USERINFO)
  router.push('/login')
}
</script>
<style scoped lang="less">
.user-info {
  width: 200px;
  .el-dropdown-link {
    display: flex;
    align-items: center;
    .user-name {
      margin-left: 5px;
    }
  }
}
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
</style>
